<!doctype html>
<html lang="zh-CN">
<head>
    <title>melon管理</title>
    {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入名称"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <input type="text" name="type" lay-verify="required" autocomplete="off" placeholder="请输入分类"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生产地</label>
                    <div class="layui-input-block">
                        <input type="text" name="origin" lay-verify="required" autocomplete="off" placeholder="请输入生产地"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <input type="text" name="comment" lay-verify="required" autocomplete="off" placeholder="请输入描述"
                               class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>


{% include 'admin/common/footer.html' %}
<script>

  layui.use(['form', 'jquery'], function() {
    let form = layui.form;
    let $ = layui.jquery;
    form.on('submit(user-save)', function(data) {
        console.log(data)
      $.ajax({
        url: '/api/v1/melons/melon',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function(result) {
          if (result.success) {
            layer.msg(result.message, {icon: 1, time: 1000}, function() {
              parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
              parent.layui.table.reload('tables');
            });
          } else {
            layer.msg(result.message, {icon: 2, time: 1000});
          }
        },
      });
      return false;
    });
  });
</script>
</body>
</html>